/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlanPanel.java
 *
 * Created on 2009-9-11, 14:50:05
 */

package jdh;

import javax.swing.table.*;
import javax.swing.RowFilter;

/**
 *
 * @author tale
 */
public class PlanPanel extends javax.swing.JPanel {

    /** Creates new form PlanPanel */
    public PlanPanel(Backend backend) {
        initComponents();
        this.backend = backend;
        Do.setBackend(backend);
        DataModel.setBackend(backend);
        LineModel.setBackend(backend);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel6 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        studentInList = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        addStudentButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        studentOutList = new javax.swing.JList();
        deleteStudentButton = new javax.swing.JButton();
        planSearch = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        classOutTable = new javax.swing.JTable();
        jPanel11 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        classInTable = new javax.swing.JTable();
        jPanel12 = new javax.swing.JPanel();
        deleteClassButton = new javax.swing.JButton();
        addClassButton = new javax.swing.JButton();
        deletePlanButton = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        planTable = new javax.swing.JTable();
        addPlanButton = new javax.swing.JButton();
        searchButton = new javax.swing.JButton();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jdh.JdhApp.class).getContext().getResourceMap(PlanPanel.class);
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel6.border.title"))); // NOI18N
        jPanel6.setName("jPanel6"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        studentInList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        studentInList.setName("studentInList"); // NOI18N
        jScrollPane2.setViewportView(studentInList);

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        addStudentButton.setText(resourceMap.getString("addStudentButton.text")); // NOI18N
        addStudentButton.setName("addStudentButton"); // NOI18N
        addStudentButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addStudentButtonActionPerformed(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        studentOutList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        studentOutList.setName("studentOutList"); // NOI18N
        jScrollPane4.setViewportView(studentOutList);

        deleteStudentButton.setText(resourceMap.getString("deleteStudentButton.text")); // NOI18N
        deleteStudentButton.setName("deleteStudentButton"); // NOI18N
        deleteStudentButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteStudentButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(addStudentButton)
                    .addComponent(deleteStudentButton))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
                    .addComponent(jLabel2))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(addStudentButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(deleteStudentButton)))
                .addContainerGap())
        );

        planSearch.setFont(resourceMap.getFont("planSearch.font")); // NOI18N
        planSearch.setText(resourceMap.getString("planSearch.text")); // NOI18N
        planSearch.setName("planSearch"); // NOI18N
        planSearch.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                planSearchFocusGained(evt);
            }
        });

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel7.border.title"))); // NOI18N
        jPanel7.setName("jPanel7"); // NOI18N

        jPanel8.setName("jPanel8"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        classOutTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Title 1", "Title 2"
            }
        ));
        classOutTable.setName("classOutTable"); // NOI18N
        classOutTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane5.setViewportView(classOutTable);
        classOutTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("classOutTable.columnModel.title0")); // NOI18N
        classOutTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("classOutTable.columnModel.title1")); // NOI18N

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                    .addComponent(jLabel4))
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel11.setName("jPanel11"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        classInTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Title 1", "Title 2"
            }
        ));
        classInTable.setName("classInTable"); // NOI18N
        classInTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(classInTable);
        classInTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("classInTable.columnModel.title0")); // NOI18N
        classInTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("classInTable.columnModel.title1")); // NOI18N

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel12.setName("jPanel12"); // NOI18N

        deleteClassButton.setText(resourceMap.getString("deleteClassButton.text")); // NOI18N
        deleteClassButton.setName("deleteClassButton"); // NOI18N
        deleteClassButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteClassButtonActionPerformed(evt);
            }
        });

        addClassButton.setText(resourceMap.getString("addClassButton.text")); // NOI18N
        addClassButton.setName("addClassButton"); // NOI18N
        addClassButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addClassButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(deleteClassButton)
                    .addComponent(addClassButton))
                .addContainerGap())
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addClassButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(deleteClassButton)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                        .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(83, 83, 83))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel11, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())))
        );

        deletePlanButton.setText(resourceMap.getString("deletePlanButton.text")); // NOI18N
        deletePlanButton.setName("deletePlanButton"); // NOI18N
        deletePlanButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deletePlanButtonActionPerformed(evt);
            }
        });

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        planTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        planTable.setName("planTable"); // NOI18N
        planTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                planTableMouseClicked(evt);
            }
        });
        planTable.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                planTableKeyPressed(evt);
            }
        });
        jScrollPane3.setViewportView(planTable);

        addPlanButton.setText(resourceMap.getString("addPlanButton.text")); // NOI18N
        addPlanButton.setName("addPlanButton"); // NOI18N
        addPlanButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPlanButtonActionPerformed(evt);
            }
        });

        searchButton.setText(resourceMap.getString("searchButton.text")); // NOI18N
        searchButton.setName("searchButton"); // NOI18N
        searchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 802, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(12, 12, 12)
                        .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(addPlanButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(deletePlanButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 342, Short.MAX_VALUE)
                        .addComponent(planSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(searchButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addPlanButton)
                    .addComponent(deletePlanButton)
                    .addComponent(searchButton)
                    .addComponent(planSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void planTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_planTableMouseClicked
        planTableChanged();
}//GEN-LAST:event_planTableMouseClicked

    private void planTableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_planTableKeyPressed
        planTableChanged();
}//GEN-LAST:event_planTableKeyPressed

    private void addPlanButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPlanButtonActionPerformed
        Do.addPlan();
        ((DataModel)planTable.getModel()).refresh();
        planTable.updateUI();
}//GEN-LAST:event_addPlanButtonActionPerformed

    private void addStudentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addStudentButtonActionPerformed
        Object value = studentOutList.getSelectedValue();
        if (value == null) return;
        Do.addLearning(getCurrentID(), value.toString());
        updateAll();
    }//GEN-LAST:event_addStudentButtonActionPerformed

    private void deleteStudentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteStudentButtonActionPerformed
        Object value = studentInList.getSelectedValue();
        if (value == null) return;
        Do.deleteLearning(getCurrentID(), value.toString());
        updateAll();
    }//GEN-LAST:event_deleteStudentButtonActionPerformed

    private void addClassButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addClassButtonActionPerformed
        int row = classOutTable.getSelectedRow();
        Object lecture = classOutTable.getValueAt(row, 0);
        Object teacher = classOutTable.getValueAt(row, 1);
        if (lecture == null || teacher == null) return;
        Do.addClassToPlan(getCurrentID(), lecture.toString(), teacher.toString());
        updateAll();
    }//GEN-LAST:event_addClassButtonActionPerformed

    private void deleteClassButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteClassButtonActionPerformed
        int row = classInTable.getSelectedRow();
        Object lecture = classInTable.getValueAt(row, 0);
        Object teacher = classInTable.getValueAt(row, 1);
        if (lecture == null || teacher == null) return;
        Do.deleteClassFromPlan(getCurrentID(), lecture.toString(), teacher.toString());
        updateAll();
    }//GEN-LAST:event_deleteClassButtonActionPerformed

    private void deletePlanButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deletePlanButtonActionPerformed
        int i = planTable.getSelectedRowCount();
        while (i -- > 0){
            //Do.deletePlan(getCurrentID());
            ((DataModel)planTable.getModel()).delete(planTable.getSelectedRow());
        }
        int row = planTable.getSelectedRow();
        if (row > planTable.getRowCount() - 1) row = planTable.getRowCount() - 1;
        else if (row < 0) row = 0;
        planTable.setRowSelectionInterval(row, row);
        planTable.updateUI();// TODO add your handling code here:
    }//GEN-LAST:event_deletePlanButtonActionPerformed

    private void planSearchFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_planSearchFocusGained
        planSearch.selectAll();
    }//GEN-LAST:event_planSearchFocusGained

    private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
        String key = planSearch.getText();
        if (key.length() == 0)
            sorter.setRowFilter(null);
        else
            sorter.setRowFilter(RowFilter.regexFilter(key));
        sorter.sort();
    }//GEN-LAST:event_searchButtonActionPerformed

    public void updateAll(){
        classInModel.refresh();
        classOutModel.refresh();
        studentInModel.refresh();
        studentOutModel.refresh();
        
        classInTable.updateUI();
        classOutTable.updateUI();
        studentInList.updateUI();
        studentOutList.updateUI();  
    }
    
    public void initPlanPanel(){
        System.out.println("plan manager panel is initialing.");
        planModel = DataModel.getPlanModel();
        classInModel = DataModel.getClassInModel();
        classOutModel = DataModel.getClassOutMode();
        studentInModel = LineModel.getStudentInModel();
        studentOutModel = LineModel.getStudentOutModel();
        
        planTable.setModel(planModel);
        classInTable.setModel(classInModel);
        classOutTable.setModel(classOutModel);
        studentInList.setModel(studentInModel);
        studentOutList.setModel(studentOutModel);

        sorter = new TableRowSorter<TableModel>(planModel);
        wakeupPlanPanel();
    }

    public void wakeupPlanPanel(){
        int row = planTable.getSelectedRow();
        if (row == -1){
            planTable.setRowSelectionInterval(0, 0);
            planTableChanged();
        }
    }

    private void planTableChanged(){
        String id = getCurrentID();
        classInModel.setSelectID(id);
        classOutModel.setSelectID(id);
        studentInModel.setSelectID(id);
        studentOutModel.setSelectID(id);
        updateAll();
    }
    
    private String getCurrentID(){
        int column = 0;
        int row = planTable.getSelectedRow();
        column = planModel.findColumn("ID");
        return (String)planModel.getValueAt(row, column);
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Backend backend = Backend.getDefaultBackend();
                Do.backend = backend;
                PlanPanel planPanel = new PlanPanel(backend);
                planPanel.initPlanPanel();

                javax.swing.JFrame frame = new javax.swing.JFrame();
                frame.add(planPanel);
                frame.setSize(frame.getPreferredSize());
                frame.setVisible(true);  
                frame.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
            }
        });
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addClassButton;
    private javax.swing.JButton addPlanButton;
    private javax.swing.JButton addStudentButton;
    private javax.swing.JTable classInTable;
    private javax.swing.JTable classOutTable;
    private javax.swing.JButton deleteClassButton;
    private javax.swing.JButton deletePlanButton;
    private javax.swing.JButton deleteStudentButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTextField planSearch;
    private javax.swing.JTable planTable;
    private javax.swing.JButton searchButton;
    private javax.swing.JList studentInList;
    private javax.swing.JList studentOutList;
    // End of variables declaration//GEN-END:variables

    Backend backend = null;

    // 培训计划管理选项卡的表格的数据源模型
    DataModel planModel = null;
    DataModel classInModel = null;
    DataModel classOutModel = null;
    LineModel studentInModel = null;
    LineModel studentOutModel = null;

    TableRowSorter sorter = null;

}
